package com.yanlin.apipassenger.service;

import com.yanlin.apipassenger.remote.ServicePassengerUserClient;
import com.yanlin.internalcommon.dto.ResponseResult;
import com.yanlin.internalcommon.dto.TokenResult;
import com.yanlin.internalcommon.util.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.yanlin.internalcommon.constant.CommonStatusEnum.TOKEN_ERROR;

/**
 * <p>标题：UserService</p>
 * <p>功能：乘客用户业务</p>
 * <p>
 * 其他说明：
 * </p>
 * <p>审核：</p>
 * <p>重构：</p>
 * <p>创建日期：2025-06-08 17:57</p>
 *
 * @author yanlin
 */
@Service
@Slf4j
public class UserService {

    @Autowired
    private ServicePassengerUserClient servicePassengerUserClient;


    public ResponseResult getUserByAccessToken(String accessToken) {
        log.info("accessToken = {}", accessToken);
        // 解析accessToken，获取手机号
        TokenResult tokenResult = JwtUtils.checkToken(accessToken);
        if (tokenResult == null) {
            return ResponseResult.fail(TOKEN_ERROR.getCode(), TOKEN_ERROR.getValue());
        }
        String phone = tokenResult.getPhone();
        // 根据手机号查询用户
        return servicePassengerUserClient.getUserByPhone(phone);
    }
}